<template>
<view>
	<view class="item_xx" v-for="(item,index) in list" :key='index'>
		<view class="xx_l"  @click="change(item)">
			<view class="name">{{item.name}}</view>
			<view class="time">
				<view class="">
					{{item.createtime}}
				</view>
				<view :class="item.status==0?'red':'orange'">
					{{item.status==0?'未读':'已读'}}
				</view>
			</view>
		</view>
		<view class="btn_c" @click="del(item.id,index)">
			删除
		</view>
	</view>
	<view class="none_img"  v-if="list.length==0">
		<image src="https://wqq103910.oss-cn-hangzhou.aliyuncs.com/images/fuzhou/image/zwsj.png" mode="widthFix"></image>
		<view class="">暂无</view>
	</view>
</view>
</template>

<script>
	import {xx} from '@/utils/api.js' 
	export default {
		data() {
			return {
				page:1, 
				isNewRenderDone:true,
				list:[],
				type_id:''
			}
		},
		onLoad(option) {
			console.log(option)
			this.type_id = option.type_id
			this.getList()
		},
		methods: {
			getList(){
				uni.showLoading({ mask:true,
					title:'正在加载'
				})
				xx.GetMessagesList({type_id:this.type_id,page:this.page}).then(res=>{
					if(this.page==1){
						this.list= res.data.data
					}else{
						this.list.push(...res.data.data)
					}
					uni.hideLoading()
				})
			},
			change(item){
				xx.UpdateMessages({id:item.id,status:1})
				uni.navigateTo({
					url:item.url
				})
			},
			del(id,index){
				let that=this
				uni.showModal({
					title:'提示',
					content:'确定删除消息吗?',
				  success: function (res) {
						if (res.confirm) {
							xx.MessagesDel({id}).then(res=>{
								if(res.status==1){
									uni.showToast({
										title:'删除成功'
									})
									that.list.splice(index,1)
								}else{
									uni.showToast({
										title:res.msg,
										icon:'none'
									})
								}
							})
						} 
					}
				})
			}
		},
		onReachBottom() {
			// 加锁，避免在加载更多时用户频繁下拉导致的重复触发而渲染异常
			if(!this.isNewRenderDone) return;   
			this.isNewRenderDone = false
			// 模拟分页请求 (加载更多)
			this.page+=1
			this.getList()
		},
	}
</script>

<style scoped lang="scss">
.xx_l{
	width: calc(100% - 60px);
}
.btn_c{
	width: 50px;
	height: 28px;
	font-size: 14px;
	background-color: #ff9933;
	color: #fff;
	border-radius: 4px;
	line-height: 28px;
	text-align: center;
}
.item_xx{
	width: calc(100% - 28px);
	padding: 8px 14px;
	border-bottom: 1px solid #E5E5E5;
	display: flex;
	align-items: center;
	justify-content: space-between;
	.time{
		font-size: 12px;
		color: #888;
		display: flex;
		justify-content: space-between;
	}
	.red{
		color: red;
	}
	.orange{
		color: #ff9933;
	}
	.name{
		position: relative;
		font-size: 14px;
		color: #333;
		margin-bottom: 6px;
	}
	.new::after{
		position: absolute;
		content:' ';
		width: 10px;
		font-size: 10px;
		top: 0px;
		left: -14px;
		border-radius: 5px;
		background: #red;
	}
}
	.none_img{
		width: 100%;
		text-align: center;
		image{
			margin-top: 60px;
			width: 50%;
		}
		view{
			font-size: 22px;
			font-weight: 800;
			color: #ccc;
		}
	}
</style>
